/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

/**
 *
 * @author Mateusz
 */
import java.sql.*;
import java.math.BigInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MySqlConnect 
{

	public static void vote(BigInteger votecode) 
	{
        try {
            Connection con = null;
            String dbname = "evoting";
            String dbuname = "alzharasoftware";
            String dbpassword = "rQdNAeT5zbFFaey2";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            con = DriverManager.getConnection("jdbc:mysql://213.227.94.232:3306\\" + dbname, dbuname, dbpassword);
            if(!con.isClosed())
            {
                    Statement stmt = con.createStatement();
                    stmt.executeQuery( "insert into glosy values (((select id from votes order by desc limit 1)+1),"+votecode+")");
                    con.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        }
	}
	public static void glosujacy(int pesel, String imie, String nazwisko, String adres) 
	{
        try {
            Connection con = null;
            String dbname = "evoting";
            String dbuname = "alzharasoftware";
            String dbpassword = "rQdNAeT5zbFFaey2";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            con = DriverManager.getConnection("jdbc:mysql://213.227.94.232:3306\\" + dbname, dbuname, dbpassword);
            if(!con.isClosed())
            {
                    Statement stmt = con.createStatement();
                    stmt.executeQuery("insert into glosujacy values ("+pesel+", "+imie+", "+nazwisko+", "+adres+")");
                    con.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MySqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        }
	}
//	public static int iloscglosow()
//	{
//		
//		Connection con = null;
//		String dbname = "evoting";
//		String dbuname = "alzharasoftware";
//		String dbpassword = "rQdNAeT5zbFFaey2";
//		Class.forName("com.mysql.jdbc.Driver").newInstance();
//		con = DriverManager.getConnection("jdbc:mysql://213.227.94.232:3306\\" + dbname, dbuname, dbpassword);
//		if(!con.isClosed())
//		{
//			Statement stmt = con.createStatement();
//			stmt.executeQuery( "select id from votes order by desc limit 1");
//			int x = stmt.getInt("id");
//			con.close();
//			return x;
//		}
//	}
//	public static BigInt glos(int id)
//	{
//		
//		Connection con = null;
//		String dbname = "evoting";
//		String dbuname = "alzharasoftware";
//		String dbpassword = "rQdNAeT5zbFFaey2";
//		Class.forName("com.mysql.jdbc.Driver").newInstance();
//		con = DriverManager.getConnection("jdbc:mysql://213.227.94.232:3306\\" + dbname, dbuname, dbpassword);
//		if(!con.isClosed())
//		{
//			Statement stmt = con.createStatement();
//			stmt.executeQuery( "select glos from votes where id="+id")");
//			BigInt x = stmt.getInt("glos");
//			con.close();
//			return x;
//		}
//	}
}